#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author  : lei.wang
import uuid as uuid_pkg
import pytz
from datetime import datetime
from typing import Optional
from sqlalchemy import String, DateTime, JSON
from sqlalchemy.orm import Mapped, mapped_column
from app.core.db.database import Base


time_zone = pytz.timezone('Asia/Shanghai')


class ChatMessages(Base):
    __tablename__ = "chat_messages"

    id: Mapped[int] = mapped_column("id", autoincrement=True, nullable=False, unique=True, primary_key=True, init=False, comment='主键id')
    uuid: Mapped[uuid_pkg.UUID] = mapped_column(default_factory=uuid_pkg.uuid4, nullable=True, index=True, comment='业务uuid')

    payload_id: Mapped[str] = mapped_column(String(255), nullable=True, default='', comment='用户标识')

    message: Mapped[Optional[dict]] = mapped_column(JSON, nullable=True, default='', comment="用户聊天记录")

    created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default_factory=lambda: datetime.now(time_zone), comment='创建时间')
    updated_at: Mapped[Optional[datetime]] = mapped_column(DateTime(timezone=True), default=None, comment='更新时间')
    is_deleted: Mapped[bool] = mapped_column(default=False, index=True, comment='是否删除')
